//
//  ByCellRecordListItem.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellRecordListItem.h"

@implementation ByCellRecordListItem
{
    UILabel     *_dateLabel;        // 时间
    UIImageView *_tagView;          // 标识符（+，-）
    UILabel     *_moneyLabel;       // 金额
 
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    // 线条
    UIView *line = [UIView new];
    line.backgroundColor = BY_LINE_COLOR;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.equalTo(@1);
    }];         
    
    // 时间
    _dateLabel = [[UILabel alloc] init];
    _dateLabel.adjustsFontSizeToFitWidth = true;
    _dateLabel.numberOfLines = 1;
    _dateLabel.text = @"2012-5-12 22:22:22";
    _dateLabel.font = FONT(16);
    _dateLabel.textAlignment = NSTextAlignmentLeft;
    _dateLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_dateLabel];
    
    // 标识符
    _tagView = [UIImageView new];
    [self.contentView addSubview:_tagView];
    
    // 金额
    _moneyLabel = [[UILabel alloc] init];
    _moneyLabel.adjustsFontSizeToFitWidth = true;
    _moneyLabel.numberOfLines = 1;
    _moneyLabel.text = @"+500";
    _moneyLabel.font = FONT(16);
    _moneyLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_moneyLabel];
    
    // 布局
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.bottom.equalTo(@0);
        make.right.lessThanOrEqualTo(_tagView.mas_left).offset(-10);
    }];
    [_tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.equalTo(@0);
        make.right.equalTo(_moneyLabel.mas_left).offset(-10);
    }];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(@0);
        make.right.equalTo(@-10);
        make.width.equalTo(self.contentView).multipliedBy(0.2);
    }];
}

- (void)setStatus:(NSInteger)status {
    
    _status = status;
    
    // 盈利
    if (status == 0) {
        self.backgroundColor = [UIColor whiteColor];
        _tagView.image = [UIImage imageNamed:@"+盈"];
        _moneyLabel.textColor = BY_YELLOW_COLOR;
    }
    else {
        self.backgroundColor = BY_BG_COLOR;
        _tagView.image = [UIImage imageNamed:@"-亏"];
        _moneyLabel.textColor = BY_BLUE_COLOR;

    }
}
@end
